<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @package     Pages Module
 * @author      Matrix Infoline (infolinematrix@gmail.com
 * @copyright   (c) Matrix Infoline
 */

class Profile extends Frontend_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->template->set_layout('member_layout');
		$this->template->set_partial('header', 'header/header');
        $this->template->set_partial('footer', 'footer/footer');
		$this->member_model->check_logedin();
	}

	function index()
	{
		$data['title'] = "Member Profile";

		//$data['profile'] = Member_model::getPk(get_session('mem_id'));

		$data['profile'] = getPK('member',get_session('mem_id'));

		$data['region'] = $this->location_model->getLocation(0,9999);

		$data['city']= $this->location_model->getCities($data['profile']['region']);
	//	$data['cityName'] = $this->location_model->get_city_data(1427);
	//		var_dump($data['cityName']);die();

		//-- Clear Session Data
		
		//BREADCRUMB//
		$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
		$this->template->set_breadcrumb('Member', 'member/profile');
		$this->template->set_breadcrumb('Profile');

		$this->template->build('profile',$data);
			
	}

	function update()
	{
		$this->form_validation->set_rules('full_name','Full Name','required|xss_clean');
		$this->form_validation->set_rules('gender','Full Name','xss_clean');
		$this->form_validation->set_rules('region','Full Name','xss_clean');
		$this->form_validation->set_rules('city','Full Name','xss_clean');
		$this->form_validation->set_rules('phone_no','Full Name','xss_clean');

			if($this->form_validation->run() == True){
				
				
			$post_data = array(
						
					'name' => $this->input->post('full_name'),
					'gender' => $this->input->post('gender'),
					'region' => $this->input->post('region'),
					'city' => $this->input->post('city'),
					'phone_no' => $this->input->post('phone_no'),
			);
				
			//var_dump($post_data);die();
			
			$this->db->where('id',get_session('mem_id'));
			$this->db->update('member',$post_data);
			$msg = "<div class='alert alert-success'> Updated Successfully...</div>";
	//		$msg = "Updated Successfully...";
			$this->session->set_flashdata('message', $msg);
			redirect('member/profile');
		}else{

			$this->index();	
				
		}

	}


}
